home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / cstdio.arc / SRC.ARC / LMOVE.A < prev    next >
Text File  |  1984-12-27  |  1KB  |  67 lines

  1. ;    lmove.a - intersegment move.
  2. ;    (C) Copyright 1984 Cray Research Inc. - All Rights Reserved.
  3. ;    G. R. Mansfield.  84/12/26.
  4. ;    Ver 1.0-4C27.
  5.  
  6.  
  7.     cseg
  8.     public    _lmove_
  9.  
  10.  
  11. ;    lmove(count, s, sseg, d, dseg)    /* intersegment move */
  12. ;    SEGSIZE count;    /* number of bytes to move */
  13. ;    BYTE *s, *d;    /* source, destination offsets */
  14. ;    SEGBASE sseg, dseg;    /* source, destination segments */
  15.  
  16. _lmove_:
  17.     mov    bx,sp
  18.     mov    cx,[bx+2]    ; count
  19.     jcxz    lmv3        ; if nothing to move
  20.     mov    si,[bx+4]    ; source offset
  21.     mov    ax,[bx+6]    ; source segment
  22.     mov    di,[bx+8]    ; destination offset
  23.     mov    bx,[bx+10]    ; destination segment
  24.     push    ds
  25.     push    es
  26.     mov    ds,ax        ; ax = abcd
  27.     mov    es,bx
  28.     push    cx        ; compare effective addresses
  29.     mov    cx,4
  30.     rol    ax,cl        ; ax = bcda
  31.     rol    bx,cl
  32.     mov    dh,al        ; dh = da; upper 4 of 20-bit address
  33.     mov    dl,bl
  34.     and    dx,00F0Fh    ; dh = 0a
  35.     xor    al,dh        ; ax = bcd0
  36.     xor    bl,dl
  37.     add    ax,si        ; ax = bcd0 + ABCD; 20-bit address
  38.     adc    dh,ch        ; dh,ax = 0abcd0 + ABCD; (ch = 0)
  39.     add    bx,di
  40.     adc    dl,ch
  41.     sub    dh,dl        ; destination - source
  42.     sbb    ax,bx
  43.     pop    cx
  44.     jz    lmv2        ; if null move
  45.     ja    lmv4        ; if (source > destination), no overlap
  46.     std            ; move from end of region
  47.     add    si,cx
  48.     add    di,cx
  49.     dec    si
  50.     dec    di
  51.     shr    cx,1
  52.     jnb    lmv1        ; move byte if necessary
  53.     movsb
  54. lmv1:    dec    si
  55.     dec    di
  56.     repz movsw
  57.     cld
  58. lmv2:    pop    ds
  59.     pop    es
  60. lmv3:    ret
  61.  
  62. lmv4:    shr    cx,1        ; move from start of region
  63.     repz movsw
  64.     jnb    lmv2        ; move remaining byte
  65.     movsb
  66.     jmp    lmv2
  67.